$(function() {
         window.addEventListener("selectstart", function(e) {
                 e.preventDefault();
             })
             //初始化地址
         init();




        $(".squares").click(function(){
            $(".guanggao img").hide()
            $(".squares").hide()
           $(".partone").css("height",0)
            return false
        })
        
    
        // var first = document.querySelector(".header .logo img")
        // var imga = document.querySelector(".header .logo img.imga")
        // first.onmouseenter = function () {
        // imga.src = './img/4171db4ecff2e253.gif'
        // }
        // first.onmouseleave = function (){
        //          setTimeout(function () {
        //          imga.src = './img/xxxxxx.jpg'
        //          },5000)
        // }


             $(".part1a a").hover(function(){
             $(this).css("background-color","#f00")
             },function(){$(this).css("background-color","burlywood")})


            $(".main .banner-left .qaqa").hover(function(){
                $(".zuocedaohanglan").css("display","block")
                },function(){$(".zuocedaohanglan").css("display","none")})
         //初始化秒杀部分轮播图
         function init() {
             //从本地存储获取上次选择的地址 有则给其添加样式，无则默认为北京
             if (localStorage.getItem("address") !== null) {
                 $(".province").html(localStorage.getItem("address"));
             } else {
                 $(".province").html("北京");
             }
     
             if (localStorage.getItem("id") !== null) {
                 $(".country ul li").eq(localStorage.getItem("id") - 1).children("a").css({
                     "backgroundColor": "#C81623",
                     "color": "white"
                 });
             } else {
                 $(".country ul li").eq(7).children("a").css({
                     "backgroundColor": "#C81623",
                     "color": "white"
                 });
             }
         }
     
         $(".advertisement .cross").on("click", function() {
             $(".top").hide();
         });
     
         var t = setInterval(function() {
             if ($(".word-change").html() == "好物重逢价") {
                 $(".word-change").html("家具双十二");
             } else {
                 $(".word-change").html("好物重逢价");
             }
     
         }, 3000);
         //外国图标
         $(".foreign  span,.foreign-country span").each(function(i, e) {
             if (i <= 2 || i >= 5 && i <= 7) {
                 $(e).css({
                     "background": "url(images/flag.png) no-repeat " + i % 5 * -20 + "px 0 ",
                     "display": "block",
                     "width": "17px",
                     "height": "12px",
                     "vertical": "middle"
                 });
             } else {
                 $(e).css({
                     "background": "url(images/flag.png) no-repeat " + i % 2 * -20 + "px -16px",
                     "display": "block",
                     "width": "17px",
                     "height": "12px",
                     "vertical": "middle"
                 });
             }
         });
     
     $(".my-jd").mouseover(function(){
        $(".my-jd-one").show()
     })

         $(".select-country").hover(function() {
             $(this).children("span").css("backgroundColor", "white");
             $(this).children(".country").toggle();
         }, function() {
             $(this).children("span").css("backgroundColor", "#E3E4E5");
             $(this).children(".country").toggle();
         });
         //改变地址
         $(".country li a").on("click", function() {
             $(this).css({
                 "backgroundColor": "#C81623",
                 "color": "white"
             });
             $(this).parent().siblings("li").children("a").css({
                 "backgroundColor": "#fff",
                 "color": "#666"
             });
             $(".province").html($(this).html());
             //本地存储地址
             localStorage.setItem("address", $(".province").html());
             localStorage.setItem("id", $(this).prop("id"));
         });
         $(".gat a").on("click", function() {
             $(".province").html($(this).html());
             $(this).addClass("style-red").siblings().removeClass("style-red");
         });
     
         $("#main").on("focus", function() {
             if ($(this).val() == "黄金手链") {
                 $(this).val("");
             }
         });
     
     
         $("#main").on("blur", function() {
             if ($(this).val() == "") {
                 $(this).val("黄金手链");
             }
         });
         //小li下滑
         $(".more").hover(function() {
             $(this).toggleClass("hover").find("section").toggle();
         });
         $(".code").hover(function() {
             $(".phone-box").toggle();
         });
     
        //  service-list图片切换
         $(".service-list a").hover(function() {
             $(this).children(".icon-prev").toggle().siblings(".icon-hover").toggle();
         });
     
         $(".service-list ul li").each(function(i, e) {
             if (i < 3) {
                 $(e).on("mouseenter", function() {
                     $(".service").stop().slideDown();
                 })
             }
         });
        $(".nav-tab li").hover(function() {
             $(this).siblings("li").children("section").hide();
             $(this).css("border-bottom", "2px solid red").children("section").show();
     
         }, function() {
             $(this).css("border-bottom", "");
         });
         $(".huafei .cross").on("click", function() {
             $(".service").stop().slideUp();
         });
     
         //若卷去窗口部分等于秒杀到顶部距离时，导航栏出现
        
     
         //侧边栏事件
         $(".backTop").on("click", function() {
             $("html").animate({
                 "scrollTop": "0"
             }, 500);
         });
         $(".jd-ms").on("click", function() {
             $("html").animate({
                 "scrollTop": $(".second-kill").offset().top - 120
             }, 1000);
         });
         $(".ts-yx").on("click", function() {
             $("html").animate({
                 "scrollTop": $(".special-choose").offset().top - 120
             }, 1000);
         });
         $(".pd-gc").on("click", function() {
             $("html").animate({
                 "scrollTop": $(".ground").offset().top - 120
             }, 1000);
         });
         $(".wn-tj").on("click", function() {
             $("html").animate({
                 "scrollTop": $(".recommend").offset().top - 120
             }, 1000);
         });
         //底部服务部分
         $(".footer-service li").each(function(i, e) {
             $(e).children("h5").css("background", "url(images/dkhs.png) no-repeat -" + i * 41 + "px -192px ");
         });
         $(".copyright-auth a").each(function(i, e) {
             $(e).css("background", "url(images/dkhs.png) no-repeat -205px -" + i * 37 + "px");
         });
         //优选部分
         $(".discount-content").each(function(i, e) {
             if (i == 0) {
                 $(e).show();
             } else {
                 $(e).hide();
             }
         });
         $(".hd li").on("mouseenter", function() {
             var index = $(this).index();
             $(".discount-content").eq(index).show().siblings(".discount-content").hide();
             $(this).children("a").css({
                 "border-bottom": "2px solid red",
                 "color": "red"
             });
             $(this).siblings("li").children("a").css({
                 "border-bottom": "",
                 "color": "#666"
             });
         });
         $(".li-two-top a").on("mouseenter", function() {
             $(this).addClass("active").siblings("a").removeClass("active");
             var index = $(this).index();
             $(".li-two-content ul li").eq(index).show().siblings("li").hide();
         });
     
     
         // 发现好货动画
         //动画定时器
         var timer = setInterval(timeOut, 20);
         $(".choose-contain-two").hover(function() {
             //鼠标移入清除定时器
             clearInterval(timer);
             $(".slide").show();
         }, function() {
             // 鼠标移出添加定时器
             // 添加前先清除 防止叠加
             clearInterval(timer);
             timer = setInterval(timeOut, 20);
             $(".slide").hide();
         });
         //动画的left值
         var left = 0;
         //定时器函数
         function timeOut() {
             left++;
             var slideWidth = $(".slide").width() - 60;
             $(".choose-contain-two ul").css("left", -left);
             $(".choose-contain-two .block").css("left", left * slideWidth / 2000);
             if (left >= 2000) {
                 left = 0;
             }
         }
         //下面的小滑块事件
         $(".block").on("mousedown", function(e) {
             //获取鼠标和滑块初始位置
             var pageLeft = e.pageX;
             var blockLeft = $(this).position().left;
             //鼠标按下移动
             //绑定在window防止鼠标竖直方向移动
             $(window).on("mousemove", function(e) {
                 //计算鼠标移动距离和滑块的位置
                 var spaceX = e.pageX - pageLeft;
                 var space = blockLeft + spaceX;
                 var slideWidth = $(".slide").width() - 60;
                 if (space < 0) {
                     space = 0;
                 } else if (space > slideWidth) {
                     space = slideWidth;
                 }
                 //滑块随鼠标移动
                 $(".block").css("left", space);
                 //按比例计算出动画的移动距离
                 left = space * 2000 / (slideWidth);
                 $(".choose-contain-two ul").css("left", -left);
     
             });
             $(window).on("mouseup", function() {
                 //鼠标释放注销事件
                 $(window).off("mousemove");
                 clearInterval(timer);
                 timer = setInterval(timeOut, 20);
             });
         });
     



         //为你推荐 固定部分 上面的小导航栏


         


         
        //  为你推荐 列表点击
         $(".recommend .tab  li").eq(0).addClass("selected");
         $(".recommend-fixed li").eq(0).addClass("selected");
     
         $(".recommend .tab  li").on("click", function() {
             $(this).eq(0).addClass("selected").siblings("li").removeClass("selected");
             //同步固定部分
             var index = $(this).index();
             $(".recommend-fixed li").eq(index).addClass("selected").siblings("li").removeClass("selected");
             //点击后跳到顶部
             $("html").animate({
                 "scrollTop": $(".recommend").offset().top - 120
             }, 300);
             //点击列表，相应列表出现
         });
         $(".recommend-fixed li").on("click", function() {
             $(this).eq(0).addClass("selected").siblings("li").removeClass("selected");
             var index = $(this).index();
             $(".recommend .tab  li").eq(index).addClass("selected").siblings("li").removeClass("selected");
             $("html").animate({
                 "scrollTop": $(".recommend").offset().top - 120
             }, 300);
         });
     });



     
     $(function() {
        init();
        function init() {
            setTime();
            set();
            setInterval(setTime, 1000);;
            setInterval(set, 1000);
        }
        //获取几点场的秒杀时间
        function targetTime(time) {
            if (time < 2) {
                return "2:00";
            } else if (time < 4) {
                return "4:00";
            } else if (time < 6) {
                return "6:00";
            } else if (time < 8) {
                return "8:00";
            } else if (time < 10) {
                return "10:00";
            } else if (time < 12) {
                return "12:00";
            } else if (time < 14) {
                return "14:00";
            } else if (time < 16) {
                return "16:00";
            } else if (time < 18) {
                return "18:00";
            } else if (time < 20) {
                return "20:00";
            } else if (time < 22) {
                return "22:00";
            } else {
                return "00:00";
            }
        }
        //返回当前时间
        function time() {
            var now = new Date();
            return [now.getFullYear(), parseInt(now.getMonth()) + 1, now.getDate(), now.getHours(), now.getMinutes(), now.getSeconds()];
        }
        //设置几点场
        function setTime() {
            $(".time").html(targetTime(time()[3]));
    
        }
        //
        function set() {
            var targetHour = targetTime(time()[3]);
            var date = targetHour == "00:00" ? parseInt(time()[2]) + 1 : time()[2];
            //获取目标时间毫秒
            var target = +new Date("" + time()[0] + "-" + time()[1] + "-" + date + " " + targetHour);
            //获取当前时间毫秒
            var now = +new Date();
            var distance = (target - now) / 1000;
    
            var hour = parseInt(distance / 60 / 60 % 24);
            var minutes = parseInt(distance / 60 % 60);
            var second = parseInt(distance % 60);
            hour = hour >= 10 ? hour : "0" + hour;
            minutes = minutes >= 10 ? minutes : "0" + minutes;
            second = second >= 10 ? second : "0" + second;
    
            $(".hour").html(hour);
            $(".minutes").html(minutes);
            $(".second").html(second);
    
        }
    
    })

    